//
//  UIBarButtonItem+Extensions.swift
//  微博(学习)
//
//  Created by yhy on 16/9/5.
//  Copyright © 2016年 yhy. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    /// 创建 UIBarButtonItem
    ///
    /// - parameter title:      title
    /// - parameter fontSize:   fontSize:默认 16 号
    /// - parameter target:     target
    /// - parameter action:     action
    /// - parameter
    ///
    /// - returns : UIBarButtonItem
    convenience init(title: String, fontSize: CGFloat = 16, target: AnyObject?, action: Selector, isBack: Bool = false) {
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        if isBack {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named: imageName), for: UIControlState(rawValue: 0))
            btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
            
            btn.sizeToFit()
            
        }
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        // 实例化 UIBarButtonItem
        self.init(customView: btn)
        
    }
}
